<template>
    <div class="advert app-wrapper">
        <div class="advert-main">
            <img :src="advert_img" alt="" class="img-advert" @click="goTarget">
        </div>
        <div class="advert-action-bar">

            <div class="advert-action-list" v-if="times > 0">
                <div class="advert-action-icon">
                    <i class="icon img-icon-home"></i>
                    <p>首页</p>
                </div>
                <div class="advert-action-icon active">
                    <i class="icon img-icon-user"></i>
                    <p>我的</p>
                </div>
            </div>
            <div class="advert-action-list" v-else>
                <router-link to="/" class="advert-action-icon">
                    <i class="icon img-icon-home"></i>
                    <p>首页</p>
                </router-link>
                <router-link to="/mine" class="advert-action-icon active">
                    <i class="icon img-icon-user"></i>
                    <p>我的</p>
                </router-link>
            </div>
            <div class="button-groups">
                <span class="button" v-if="times > 0">进入直播</span>
                <router-link to="/" type="button" class="button" v-else>进入直播</router-link>
            </div>
        </div>

        <div class="count-down"><span>{{times}}</span>S</div>
    </div>
</template>

<script>

export default {
    components: {},
    props: {},
    data() {
        return {
            advert_url: '/live/35' || '',
            advert_img: require('@/assets/img/advert_01.jpg'),
            times: 5,
            timer: null
        };
    },
    computed: {},
    methods: {
        goTarget(){
            if(!this.advert_url) return false;
            if(this.advert_url.indexOf('http') > -1) location.href = this.advert_url;
            return this.$router.push(this.advert_url);
        },
        timeCountDown(){
            if(this.timer) clearTimeout(this.timer);
            if(this.timer == null){
                setTimeout(()=>{
                    if(this.times > 0){
                        this.times--;
                        this.timeCountDown();
                    } else {
                        clearTimeout(this.timer);
                    }
    
                }, 1000);
            }
        }
    },
    created() {},
    mounted() {
        this.timeCountDown();
    }
};
</script>
<style lang="scss" scoped>
.advert {
    padding-bottom: 112px;
    .advert-main {
        height: 100%;
        position: relative;
        background: yellowgreen;
        overflow: hidden;
        
        > .img-advert {
            width: 100%;
        }
    }

    .count-down {
        height:48px;
        padding: 0 20px;
        position: absolute;
        right: 20px;
        top: 20px;
        font-size: 24px;
        color: #fff;
        line-height: 48px;
        background-color: rgba(0,0,0, .4);
        border-radius: 32px;
    }
}

.advert-action-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 12px 35px;
    font-size: 0;
    background: #fff;

    .advert-action-list {
        display: flex;
    }

    .button-groups { flex: 1; }
    .advert-action-icon{
        width: 100px;
        text-align: center;
        color: #666;


        .icon {
            display: inline-block;
            width: 40px;
            height: 48px;
            background-size: contain;
        }

        p { font-size: 24px; }
    }

    .button{
        display: block;
        width: 100%;
        height: 80px;
        font-size: 32px;
        color: #fff;
        line-height: 80px;
        text-align: center;
        background-color: #0084ff;
    }
}
</style>